package com.hqd.ch03.v51.boot.context.properties.bind.validation.beanvalidation;

import com.hqd.ch03.v51.core.annotation.MergedAnnotations;

import java.lang.annotation.Annotation;

public interface MethodValidationExcludeFilter {

    /**
     * Factory method to create a {@link MethodValidationExcludeFilter} that excludes
     * classes by annotation found using an {@link SearchStrategy#INHERITED_ANNOTATIONS
     * inherited annotations search strategy}.
     *
     * @param annotationType the annotation to check
     * @return a {@link MethodValidationExcludeFilter} instance
     */
    static MethodValidationExcludeFilter byAnnotation(Class<? extends Annotation> annotationType) {
        return byAnnotation(annotationType, MergedAnnotations.SearchStrategy.INHERITED_ANNOTATIONS);
    }

    /**
     * Factory method to create a {@link MethodValidationExcludeFilter} that excludes
     * classes by annotation found using the given search strategy.
     *
     * @param annotationType the annotation to check
     * @param searchStrategy the annotation search strategy
     * @return a {@link MethodValidationExcludeFilter} instance
     */
    static MethodValidationExcludeFilter byAnnotation(Class<? extends Annotation> annotationType,
                                                      MergedAnnotations.SearchStrategy searchStrategy) {
        return (type) -> MergedAnnotations.from(type, searchStrategy).isPresent(annotationType);
    }

    /**
     * Evaluate whether to exclude the given {@code type} from method validation.
     *
     * @param type the type to evaluate
     * @return {@code true} to exclude the type from method validation, otherwise
     * {@code false}.
     */
    boolean isExcluded(Class<?> type);

}
